package com.yungu.swift.base.model.api;

import io.swagger.annotations.ApiModelProperty;

import java.util.Optional;

/**
 * @author : cuixiuyin
 * @date : 2019/8/28
 */
public class ApiPageParam extends ApiParam {

    private final Integer MIN_PAGE = 1;
    private final Integer MAX_PAGE = 10000;
    private final Integer DEFAULT_PAGE_SIZE = 10;

    @ApiModelProperty(value = "当前页数")
    private Integer nowPage = MIN_PAGE;

    @ApiModelProperty(value = "每页数据量")
    private Integer pageSize = DEFAULT_PAGE_SIZE;

    public ApiPageParam() {
    }

    public ApiPageParam(Integer pageNum) {
        this.nowPage = Optional.ofNullable(pageNum).orElse(MIN_PAGE);
        this.pageSize = DEFAULT_PAGE_SIZE;
    }

    public Integer getNowPage() {
        return nowPage;
    }

    public void setNowPage(Integer nowPage) {
        this.nowPage = nowPage;
    }

    public void setPageSize(Integer pageSize) {
        this.pageSize = pageSize;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize > MAX_PAGE ? MAX_PAGE : pageSize;
    }
}
